refactor: improve C++ code quality and add Vec2 type#21
Merged
Conversation
- Add Vec2 struct to replace std::pair<float,float> for positions and movement - Fix EnvironmentObject: make position protected, remove unnecessary virtual from getPosition/setPosition - Fix double memcpy bug in Genes constructor (delegating ctor already copies) - Fix calculateDistance: take shared_ptr by const ref instead of by value - Make react()/interact() take const vector references - Make Food::canBeEaten() const, add configurable energy via Food(int energy) constructor - Make RNG thread_local in Organism::makeMove() and Genes::defaultMutationLogic() - Remove dead removeDeadOrganisms() declaration from Environment - Pre-compute organism list before thread dispatch in handleReactions - Skip thread creation when numThreads=1 - Make handleInteractions single-threaded (mutates shared state) - Remove all commented-out printf debug statements - Use structured bindings in Environment iteration loops - Initialize foodConsumption to 0 in header - Expose Food energy constructor in Python bindings Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
YJack0000
force-pushed
the
refactor/code-quality
branch
from
February 23, 2026 20:41
b256cb9 to
41e91ac
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Vec2struct to replacestd::pair<float,float>for positions/movement — improves readability (pos.xvspos.first)EnvironmentObject: makepositionprotected, remove unnecessaryvirtualfromgetPosition/setPositionmemcpybug inGenesconstructorcalculateDistancetakingshared_ptrby value (unnecessary ref count bump)Food::canBeEaten()const, addFood(int energy)constructor for configurable energyprintfdebug statements (~20 lines)numThreads=1Discussion Points
Vec2提供了operator std::pair<float,float>()以維持向後相容。Python bindings 仍然回傳 tuple,不需要改動 Python 端程式碼EnvironmentObject::position改為protected,讓Organism可以直接存取而不需要透過 virtual dispatchFood新增Food(int energy)constructor,但預設仍然是 500,不會影響現有行為SpatialIndexTypeenum 已加入但 constructor 仍接受 string 以維持 Python API 相容性Test plan
🤖 Generated with Claude Code